/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AgregarPalabra.java
 *
 * Created on 27/05/2012, 12:13:37 AM
 */
package Miscelaneo.TiposGenericos.Demo;

import java.awt.Color;
import java.util.HashMap;
import javax.swing.JOptionPane;

/**
 *
 * @author AMD
 */
public class AgregarPalabra extends javax.swing.JFrame {
    private MiTreeMap mapDiccionario;
    private serializacion serial;
    private NewJFrameDiccionario frameDicc;
    /** Creates new form AgregarPalabra */
    public AgregarPalabra() {
        initComponents();
        serial = new  serializacion();
        mapDiccionario = new  MiTreeMap();
    }
    public AgregarPalabra(MiTreeMap mapDiccionario, serializacion serial, NewJFrameDiccionario frameDicc) {
        initComponents();
        this.setBackground(Color.CYAN);
        this.mapDiccionario = mapDiccionario;
        this.serial = serial;
        this.frameDicc = frameDicc;
    }
  
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        textAreaSignificado = new javax.swing.JTextArea();
        txt_palabra = new javax.swing.JTextField();
        btn_agregar = new javax.swing.JButton();
        btn_salir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Agregar palabra");
        setBackground(new java.awt.Color(153, 153, 255));
        setResizable(false);

        textAreaSignificado.setColumns(20);
        textAreaSignificado.setRows(5);
        textAreaSignificado.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        jScrollPane1.setViewportView(textAreaSignificado);

        txt_palabra.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        btn_agregar.setText("Agregar");
        btn_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_agregarActionPerformed(evt);
            }
        });

        btn_salir.setText("Salir");
        btn_salir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_salirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(txt_palabra, javax.swing.GroupLayout.PREFERRED_SIZE, 257, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(btn_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 64, Short.MAX_VALUE)
                .addComponent(btn_salir)
                .addContainerGap())
            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 499, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btn_salir)
                    .addComponent(txt_palabra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btn_agregar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btn_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_agregarActionPerformed
        if (!txt_palabra.getText().isEmpty() && !textAreaSignificado.getText().isEmpty()){
            try {
                mapDiccionario.put(txt_palabra.getText(), textAreaSignificado.getText());
                txt_palabra.setText("");
                textAreaSignificado.setText("");
//              if(serial.HayRegistros("diccionario.dat")){
//                      serial.SerializacionPrimaria("diccionario.dat", mapDiccionario);
//                }
//                else
                serial.SerializacionPrimaria("diccionario.dat", mapDiccionario);
                frameDicc.CargarPalabrasA_la_lista();
            //    JOptionPane.showMessageDialog(null, "Datos agregados correctamente...");
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, e.toString());
            
            }
        }
        else{
            JOptionPane.showMessageDialog(null, "Hay datos que faltan completar");
        }
    }//GEN-LAST:event_btn_agregarActionPerformed

    private void btn_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_salirActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_btn_salirActionPerformed

    /**
     * @param args the command line arguments
     */
  
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btn_agregar;
    private javax.swing.JButton btn_salir;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea textAreaSignificado;
    private javax.swing.JTextField txt_palabra;
    // End of variables declaration//GEN-END:variables
}
